package gui;


import interfaces.BankRegistry;

import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.*;

import testit.GUITest;

import money.Money;

import banking.*;

public class GUIaddMoney extends JFrame {
	
	JTextField textfield_reason;
	JTextField textfield_accountNumber;
	JTextField textfield_value;
	
	JButton	button_addMoney;
	
	JLabel label_accountNumber;
	JLabel label_reason;
	JLabel label_value;

	
	public GUIaddMoney() {

		this.getContentPane().setLayout(null);

		this.addMoneyWindow();

		this.addWindowListener(new WindowListener() {

			public void windowClosed(WindowEvent arg0) {
			}

			public void windowActivated(WindowEvent e) {
			}

			public void windowClosing(WindowEvent buttonEvent) {
			}
			
			public void windowDeactivated(WindowEvent e) {
			}

			public void windowDeiconified(WindowEvent e) {
			}

			public void windowIconified(WindowEvent e) {
			}

			public void windowOpened(WindowEvent e) {
			}
		});

	}

	public void paintComponent(Graphics g) {
	    super.paintComponents(g);
	    g.drawString("Account Number", 10, 40);
	  }
	
	public void addMoneyWindow() 
	{

		// instance
		textfield_accountNumber = new JTextField();
		textfield_reason = new JTextField();
		textfield_value = new JTextField();
		
		button_addMoney = new JButton("addMoney");
		
		label_accountNumber = new JLabel("Account Number:");
		label_reason = new JLabel("Reason:");
		label_value = new JLabel("Value:");
		
		
		//Action Listener
		button_addMoney.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				try {
					addMoney();
				} catch (Exception e) {
					e.printStackTrace();
				}
				
			}

		});
		
		// position
		textfield_accountNumber.setBounds(150,40,200,25);
		textfield_reason.setBounds(150, 80, 200, 25);
		textfield_value.setBounds(150, 120, 200, 25);
		
		button_addMoney.setBounds(75, 240, 200, 30);
		
		label_accountNumber.setBounds(10, 40, 150, 25);
		label_reason.setBounds(10, 80, 150, 25);
		label_value.setBounds(10, 120, 150, 25);
		
		
		
		// add elements
		this.getContentPane().add(textfield_accountNumber);
		this.getContentPane().add(textfield_reason);
		this.getContentPane().add(textfield_value);
		
		this.getContentPane().add(button_addMoney);
		
		this.getContentPane().add(label_accountNumber);
		this.getContentPane().add(label_reason);
		this.getContentPane().add(label_value);
		

		this.pack();
	}

	public void addMoney() throws Exception{
		
		Money money = new Money(0);
		
		int	accountNumber = Integer.parseInt(textfield_accountNumber.getText());
		String reason = textfield_reason.getText();
		money.setValue(Long.parseLong(textfield_value.getText()));
		BankImpl Sparkasse = BankRegistry.loockup("Sparkasse");
		Sparkasse.addMoney(money, reason, accountNumber);
		//Sparkasse.accountStatement(accountNumber, "text/plain");

	}
}